{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys,copy,os,inspect\n",
    "if hasattr(sys.modules[__name__], '__file__'):\n",
    "    _file_name = __file__\n",
    "else:\n",
    "    _file_name = inspect.getfile(inspect.currentframe())\n",
    "CURRENT_FILE_PATH = os.path.dirname(_file_name)\n",
    "sys.path.append(os.getcwd()+\"/../neuronVis\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "#open的第一个参数为文件名，第二个参数为打开的类型\"r\"为读,'w'为写，'a'为追加等等\n",
    "csvFile = open(\"../resource/10_slice/slice.csv\",\"r\")\n",
    "reader = csv.reader(csvFile)\n",
    "#将reader转化为list,方便进行遍历\n",
    "slice2allen =list(reader)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "position=[]\n",
    "file=[]\n",
    "\n",
    "for i in slice2allen:\n",
    "    position.append(int(i[1]))\n",
    "    file.append('../resource/10_slice/T'+i[0]+'.png')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['../resource/10_slice/T239.png',\n",
       " '../resource/10_slice/T240.png',\n",
       " '../resource/10_slice/T241.png',\n",
       " '../resource/10_slice/T242.png',\n",
       " '../resource/10_slice/T243.png',\n",
       " '../resource/10_slice/T244.png',\n",
       " '../resource/10_slice/T245.png',\n",
       " '../resource/10_slice/T246.png',\n",
       " '../resource/10_slice/T247.png',\n",
       " '../resource/10_slice/T248.png',\n",
       " '../resource/10_slice/T250.png',\n",
       " '../resource/10_slice/T251.png',\n",
       " '../resource/10_slice/T252.png',\n",
       " '../resource/10_slice/T253.png',\n",
       " '../resource/10_slice/T255.png',\n",
       " '../resource/10_slice/T256.png',\n",
       " '../resource/10_slice/T257.png',\n",
       " '../resource/10_slice/T258.png',\n",
       " '../resource/10_slice/T259.png',\n",
       " '../resource/10_slice/T260.png',\n",
       " '../resource/10_slice/T261.png',\n",
       " '../resource/10_slice/T262.png',\n",
       " '../resource/10_slice/T263.png',\n",
       " '../resource/10_slice/T264.png',\n",
       " '../resource/10_slice/T265.png',\n",
       " '../resource/10_slice/T266.png',\n",
       " '../resource/10_slice/T267.png',\n",
       " '../resource/10_slice/T268.png',\n",
       " '../resource/10_slice/T269.png',\n",
       " '../resource/10_slice/T270.png',\n",
       " '../resource/10_slice/T271.png',\n",
       " '../resource/10_slice/T272.png',\n",
       " '../resource/10_slice/T273.png',\n",
       " '../resource/10_slice/T274.png',\n",
       " '../resource/10_slice/T275.png',\n",
       " '../resource/10_slice/T276.png',\n",
       " '../resource/10_slice/T277.png',\n",
       " '../resource/10_slice/T278.png',\n",
       " '../resource/10_slice/T279.png',\n",
       " '../resource/10_slice/T280.png',\n",
       " '../resource/10_slice/T281.png',\n",
       " '../resource/10_slice/T282.png',\n",
       " '../resource/10_slice/T283.png',\n",
       " '../resource/10_slice/T284.png',\n",
       " '../resource/10_slice/T285.png',\n",
       " '../resource/10_slice/T286.png',\n",
       " '../resource/10_slice/T287.png',\n",
       " '../resource/10_slice/T288.png',\n",
       " '../resource/10_slice/T291.png',\n",
       " '../resource/10_slice/T292.png',\n",
       " '../resource/10_slice/T293.png',\n",
       " '../resource/10_slice/T294.png',\n",
       " '../resource/10_slice/T295.png',\n",
       " '../resource/10_slice/T296.png',\n",
       " '../resource/10_slice/T297.png',\n",
       " '../resource/10_slice/T299.png',\n",
       " '../resource/10_slice/T300.png',\n",
       " '../resource/10_slice/T301.png',\n",
       " '../resource/10_slice/T302.png',\n",
       " '../resource/10_slice/T303.png',\n",
       " '../resource/10_slice/T304.png',\n",
       " '../resource/10_slice/T305.png',\n",
       " '../resource/10_slice/T306.png',\n",
       " '../resource/10_slice/T307.png',\n",
       " '../resource/10_slice/T308.png',\n",
       " '../resource/10_slice/T309.png',\n",
       " '../resource/10_slice/T311.png',\n",
       " '../resource/10_slice/T312.png',\n",
       " '../resource/10_slice/T313.png',\n",
       " '../resource/10_slice/T314.png',\n",
       " '../resource/10_slice/T315.png',\n",
       " '../resource/10_slice/T316.png',\n",
       " '../resource/10_slice/T317.png',\n",
       " '../resource/10_slice/T318.png',\n",
       " '../resource/10_slice/T319.png',\n",
       " '../resource/10_slice/T321.png',\n",
       " '../resource/10_slice/T322.png',\n",
       " '../resource/10_slice/T323.png',\n",
       " '../resource/10_slice/T324.png',\n",
       " '../resource/10_slice/T325.png',\n",
       " '../resource/10_slice/T326.png',\n",
       " '../resource/10_slice/T329.png',\n",
       " '../resource/10_slice/T330.png',\n",
       " '../resource/10_slice/T331.png',\n",
       " '../resource/10_slice/T332.png',\n",
       " '../resource/10_slice/T333.png',\n",
       " '../resource/10_slice/T334.png',\n",
       " '../resource/10_slice/T335.png',\n",
       " '../resource/10_slice/T336.png',\n",
       " '../resource/10_slice/T337.png',\n",
       " '../resource/10_slice/T338.png',\n",
       " '../resource/10_slice/T339.png',\n",
       " '../resource/10_slice/T340.png',\n",
       " '../resource/10_slice/T341.png',\n",
       " '../resource/10_slice/T342.png',\n",
       " '../resource/10_slice/T343.png',\n",
       " '../resource/10_slice/T344.png',\n",
       " '../resource/10_slice/T345.png',\n",
       " '../resource/10_slice/T346.png',\n",
       " '../resource/10_slice/T347.png',\n",
       " '../resource/10_slice/T348.png',\n",
       " '../resource/10_slice/T349.png',\n",
       " '../resource/10_slice/T350.png',\n",
       " '../resource/10_slice/T351.png',\n",
       " '../resource/10_slice/T352.png',\n",
       " '../resource/10_slice/T353.png',\n",
       " '../resource/10_slice/T354.png',\n",
       " '../resource/10_slice/T355.png',\n",
       " '../resource/10_slice/T356.png',\n",
       " '../resource/10_slice/T357.png',\n",
       " '../resource/10_slice/T358.png',\n",
       " '../resource/10_slice/T359.png',\n",
       " '../resource/10_slice/T360.png',\n",
       " '../resource/10_slice/T361.png',\n",
       " '../resource/10_slice/T362.png',\n",
       " '../resource/10_slice/T363.png',\n",
       " '../resource/10_slice/T364.png',\n",
       " '../resource/10_slice/T365.png',\n",
       " '../resource/10_slice/T366.png',\n",
       " '../resource/10_slice/T367.png',\n",
       " '../resource/10_slice/T368.png',\n",
       " '../resource/10_slice/T369.png',\n",
       " '../resource/10_slice/T370.png',\n",
       " '../resource/10_slice/T371.png',\n",
       " '../resource/10_slice/T372.png',\n",
       " '../resource/10_slice/T373.png']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "file"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "from  RenderGL import *\n",
    "from skimage import draw, io\n",
    "\n",
    "render = RenderGL(renderModel=0)\n",
    "render.setBackgroundColor([1,1,1])\n",
    "for i in range(len(position[:])):\n",
    "    ga = GeometryAdapter.GeometryAdapter()\n",
    "    ga.geometry.addPoint([position[i]*10,0,11400],color=[1.0,1.0,1.0],texcoord = [0.11,0.07])\n",
    "    ga.geometry.addPoint([position[i]*10,0,5700],color=[1.0,1.0,.0],texcoord = [0.6,0.07])\n",
    "    ga.geometry.addPoint([position[i]*10,8000,5700],color=[1.0,1.0,.0],texcoord = [0.6,0.71])\n",
    "    ga.geometry.addPoint([position[i]*10,8000,11400],color=[1.0,1.0,.0],texcoord = [0.11,0.71])\n",
    "\n",
    "    ga.geometry.addIndex(0)\n",
    "    ga.geometry.addIndex(1)\n",
    "    ga.geometry.addIndex(2)\n",
    "    ga.geometry.addIndex(2)\n",
    "    ga.geometry.addIndex(3)\n",
    "    ga.geometry.addIndex(0)\n",
    "\n",
    "    ga.geometry.drawModel='normal'\n",
    "    img=io.imread(file[i])\n",
    "    ga.geometry.addTexture('diff',img)\n",
    "    # render.setPointSize(2)\n",
    "    render.addGeometry(ga.geometry)\n",
    "# render.setClip(True)\n",
    "# render.savepng('../resource/test3.png')\n",
    "render.run()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.3 ('neuronVis')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "e1da01a652087c3f485a2a8b69806c32fa3b3acf94bcdc0c1ef74e2af5cc794e"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
